/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
const int threshold = 10;
//int day = 0 ;
const int buttonPin = 2 ;
int buttonState = 0 ;
int lightSensorReading = 0;  
void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);   
  pinMode(buttonPin, INPUT)  ;
  Serial.begin(9600);       // use the serial port
}

void loop() {
  
  // gas and brake are assumed to be exclusive
  //accelerator   
  int sensorReading = analogRead(A0);
  if( sensorReading > 10){
    Serial.print('U');
    Serial.print(sensorReading);
    Serial.print('E');
    //delay(5) ;
  }
  else{ // brake
    sensorReading = analogRead(A1);  
    if( sensorReading > 10){
      Serial.print('D');
      Serial.print(sensorReading);
      Serial.print('E');
      //delay(5) ;
    }      
  }
  
  //reading day light and turning on and off the headlight
  sensorReading = analogRead(A2);  
  // if you need the light sensor reading in the 
  // application side, uncomment this code
  if( abs(lightSensorReading-sensorReading) > 100){
      Serial.print('L');
      Serial.print(sensorReading);
      Serial.print('E');
      lightSensorReading = sensorReading;
      //delay(5) ;
  }        
  if(sensorReading > 700){  // day      
      digitalWrite(13, LOW) ; 
  }
  else if(sensorReading < 400){  //night. So turn on the light
      digitalWrite(13, HIGH);
  }
  
  buttonState = digitalRead(buttonPin);
  if(buttonState == HIGH){
    digitalWrite(13, HIGH) ;
    Serial.print('F');
  }
  else{
    digitalWrite(13, LOW);
  }  
}
